<?php

namespace app\admin\controller;

use app\admin\middleware\Auth;
use app\model\UserFbLogModel;
use app\model\UserModel;
use think\App;

class User extends Base {

    protected $middleware = [Auth::class];
    private $model;

    private $aid;

    private $page;

    private $limit;


    public function __construct(App $app){

        parent::__construct($app);

        $this->req = request()->param();

        $this->model = new UserModel();

        $this->aid = $this->isLogin();

        $this->page = isset($this->req['page']) ? $this->req['page'] : 1;

        $this->limit = isset($this->req['limit']) ? $this->req['limit'] : 20;
    }

    /*
   * 获取用户信息
   * */
    public function getList(){

        $where = [];
        if(!empty($this->req['username'])){
            $where[] = ['username','like',"%".$this->req['username']."%"];
        }

        if(!empty($this->req['yx'])){
            $where[] = ['yx','like',"%".$this->req['yx']."%"];
        }

        if(!empty($this->req['mobile'])){
            $where[] = ['mobile','like',"%".$this->req['mobile']."%"];
        }


        $list = $this->model->getList($where,$this->page,$this->limit,"create_at", "DESC");

        $total =  $this->model->getTotal($where);

        $userFbLogModel = new UserFbLogModel();
        if($list){
            foreach ($list as &$item){
                $item["fb"] = $userFbLogModel->getUserTotalFb($item["uid"]);
            }
        }

        return $this->succData($total,$list);

    }



}